<script language="javascript" runat="server">

    function GOTO(destination)
    {
        interview.setPosition(destination, true);

        if (isGroupState())
        {
            return;
        }

        interview = null;

        var targetURL = new String("?screenType=intervieweeInInterview");
        var targetQuestionID = new String(Session("user_targetQuestionID"));
        // Out("GOTO RECEIVED, tqID: " + targetQuestionID);
        // Response.End();
        if (targetQuestionID.length != 0 && targetQuestionID != "undefined")
        {
            targetURL += "&targetQuestionID=" + targetQuestionID;
        }
        REDIRECT_TO_PAGE(targetURL);
    }

    function FINISH_INTERVIEW()
    {
        // Save the interview data for this interviewee
        interview.finishInterview(interviewee.intervieweeID, getRemoteUserName());
        // we are done with the current interview object

        // Set the interviewee status as completed
        interviewee.switchRecordStatus(8, String(""), getRemoteUserName());
        // we are done with the current interviewee object

        checkAndIncreaseExtraFieldQoutas();

        // interviewee = null;
        // interview = null;

        // get a new interviewee for cati
        if (!Session("WEB_SURVEY_SESSION") == "1") { Response.Redirect("?screenType=interviewerIntervieweeCall"); }

    }

    function FINISH_INTERVIEW_QOUTA_OVERFLOW()
    {
        // Save the interview data for this interviewee
        interview.finishInterview(interviewee.intervieweeID, getRemoteUserName());

        if (Session("WEB_SURVEY_SESSION") == "1") { Session("WEB_SURVEY_HAS_BEEN_COMPLETED") = "1"; }

        // we are done with the current interview object
        interview = null;

        // Set the interviewee status as qouta overflow
        interviewee.switchRecordStatus(9, String(""), getRemoteUserName());
        // we are done with the current interviewee object
        interviewee = null;
    }

    function FINISH_INTERVIEW_RENDEZVOUS()
    {
        // Save the interview data for this interviewee
        interview.finishInterview(interviewee.intervieweeID, getRemoteUserName());
        // we are done with the current interview object
        interview = null;

        // Go to the rendezvous page
        Response.Redirect("?screenType=interviewerIntervieweeRendezvous");
    }

    function FINISH_INTERVIEW_INTERRUPT()
    {
        // Save the interview data for this interviewee
        interview.finishInterview(interviewee.intervieweeID, getRemoteUserName());
        // we are done with the current interview object
        interview = null;
        // Go to the rendezvous page
        Response.Redirect("?screenType=interviewerIntervieweeNotAvailable");
    }

    function QUERY(qID, val)
    {
        return interview.QUERY(String(qID), String(val));
    }

    function ANSWER(qID)
    {
        return interview.ANSWER(String(qID));
    }

    function SETANSWER(qID, answer, openAnswer)
    {
        var targetQuestionID = new String(Session("user_targetQuestionID"));
        if ((targetQuestionID.length == 0) || (targetQuestionID == "undefined"))
            interview.setAnswer(String(qID), String(answer), String(openAnswer));
    }

    function CONTINUE()
    {
        var targetQuestionID = new String(Session("user_targetQuestionID"));
        if (targetQuestionID.length != 0 && targetQuestionID != "undefined")
        {
            Out("<sc" + "ript language=\"javascript\">document.forms[0].action += \"&targetQuestionID=" + targetQuestionID + "\";</scr" + "ipt>");
        }

        Out("<sc" + "ript language=\"javascript\">document.getElementById(\"frmQuestion\").submit();</scr" + "ipt>");
    }

    function GETANSWERTEXT(qID)
    {
        interview = Session("user_interview");
        return interview.Question(String(qID)).GetAnswer();
    }

    function RESETANSWER(qID)
    {
        var targetQuestionID = new String(Session("user_targetQuestionID"));
        if ((targetQuestionID.length == 0) || (targetQuestionID == "undefined"))
        {
            interview = Session("user_interview");
            interview.Question(String(qID)).ResetAnswer();
        }
    }

    function OPENANSWER(qID)
    {
        return interview.Question(String(qID)).openAnswer;
    }

    function QOUTACOUNT(qName)
    {
        var qoutaObject = Server.CreateObject("oxWebCATICom.CATIQouta");
        interview = Session("user_interview");
        return qoutaObject.GetQoutaCount(interview.surveyName, String(qName));
    }

    function displayInterviewDescription(interview)
    {
        if (interview.surveyName == "DANFOSS" || interview.surveyName == "DANFOSS_AFRICA")
        {
            Response.Write("<p style=\"text-align:right;background-color:#EC0928;color:white;font-size:16px;font-weight:bold;\"><img width='321' height='89' src='surveyData/DANFOSS/img/danfoss_banner.png?1' />" + "</p>");
        }
        else
        {
            Response.Write("<p style=\"text-align:center;background-color:#406080;color:white;font-size:16px;font-weight:bold;\"><br />&nbsp;&nbsp;" + getSurveyDescription(interview.surveyName) + "<br /><br /></p>");
        }
    }
</script>
